import { HttpException, NestMiddleware } from "@nestjs/common";
import { Request, Response, NextFunction } from 'express';
import { students } from '../../db';
/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-11-20 13:47:54
 * @LastEditors: GGB
 * @LastEditTime: 2021-11-20 13:51:30
 */
export class ValidStudentMiddleware implements NestMiddleware {
    use(req: Request, res: Response, next: NextFunction) {
        console.log("Middleware Called")
        const studentId = req.params.studentId;
        let studentExists = students.some(student => student.id === studentId)
        if (!studentExists) {
            throw new HttpException("student not found", 400);
        }
        next();
    }

}